package com.vanysoft.business.sys.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.vanysoft.framework.config.database.BaseEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户信息
 *
 * @author qi_ma
 */
@TableName("SYS_USER_INFO")
public class UserInfo extends BaseEntity<UserInfo> {
    private static final long serialVersionUID = -8155440945893623808L;
    /**
     * 登陆账号
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * SAP 员工号
     */
    @Excel(name = "sapStaffNo", fixedIndex = 0)
    private String sapStaffNo;
    /**
     * 员工SESA号
     */
    @Excel(name = "sesaId", fixedIndex = 1)
    private String sesaId;
    /**
     * 员工TalentLink ID
     */
    private String employeeId;
    /**
     * 中文姓名
     */
    @Excel(name = "chineseName", fixedIndex = 2)
    private String chineseName;
    /**
     * 英文名
     */
    @Excel(name = "englishName", fixedIndex = 3)
    private String englishName;
    /**
     * 名(拼音)
     */
    private String firstName;
    /**
     * 姓(拼音)
     */
    private String lastName;
    /**
     * 用户邮箱
     */
    @Excel(name = "email", fixedIndex = 4)
    private String email;
    /**
     * 业务区域
     */
    private String businessUnit;
    /**
     * 公司
     */
    private String convertCompany;
    /**
     * 部门
     */
    private String department;
    /**
     * 职位（字典）
     */
    private String businessTitleValue;
    /**
     * 职位值
     */
    @TableField(exist = false)
    @Excel(name = "businessTitleText", fixedIndex = 5)
    private String businessTitleText;
    /**
     * Job code
     */
    private String jobCode;
    /**
     * 经理SESA号
     */
    private String supervisorSesaId;
    /**
     * BU HR SESA号
     */
    private String buHrSesaId;
    /**
     * 成本中心
     */
    @Excel(name = "costCenter", fixedIndex = 6)
    private String costCenter;
    /**
     * 员工状态（字典）
     */
    private String employeeStatus;
    /**
     * 员工状态值
     */
    @TableField(exist = false)
    @Excel(name = "employeeStatusText", fixedIndex = 7)
    private String employeeStatusText;
    /**
     * 是否启用（1，0）
     */
    @Excel(name = "isEnable", fixedIndex = 9)
    private String isEnable;
    /**
     * 头像ID（附件表）
     */
    private String photoId;

    /**
     * 组织机构信息
     */
    @TableField(exist = false)
    private List<Org> orgs;

    /**
     * 用户角色列表
     */
    @TableField(exist = false)
    private List<Role> roles;

    /**
     * 用户角色ID列表
     */
    @TableField(exist = false)
    private String[] roleIds;

    /**
     * 用户角色名称列表
     */
    @TableField(exist = false)
    @Excel(name = "roleNames", fixedIndex = 8)
    private String[] roleNames;

    /**
     * 用户资源列表
     */
    @TableField(exist = false)
    private List<Menu> menus;

    public Boolean isAdmin() {
        if (roles == null) {
            return false;
        }
        return roles.stream().anyMatch(Role::getAdmin);
    }

    public List<String> getPermissions() {
        if (menus == null) {
            return new ArrayList<>();
        }
        return menus.stream().map(m -> m.getApi().getUri()).filter(StringUtils::isNotEmpty).distinct().collect(Collectors.toList());
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSapStaffNo() {
        return sapStaffNo;
    }

    public void setSapStaffNo(String sapStaffNo) {
        this.sapStaffNo = sapStaffNo;
    }

    public String getSesaId() {
        return sesaId;
    }

    public void setSesaId(String sesaId) {
        this.sesaId = sesaId;
    }

    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(String employeeId) {
        this.employeeId = employeeId;
    }

    public String getChineseName() {
        return chineseName;
    }

    public void setChineseName(String chineseName) {
        this.chineseName = chineseName;
    }

    public String getEnglishName() {
        return englishName;
    }

    public void setEnglishName(String englishName) {
        this.englishName = englishName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getBusinessUnit() {
        return businessUnit;
    }

    public void setBusinessUnit(String businessUnit) {
        this.businessUnit = businessUnit;
    }

    public String getConvertCompany() {
        return convertCompany;
    }

    public void setConvertCompany(String convertCompany) {
        this.convertCompany = convertCompany;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getBusinessTitleValue() {
        return businessTitleValue;
    }

    public void setBusinessTitleValue(String businessTitleValue) {
        this.businessTitleValue = businessTitleValue;
    }

    public String getBusinessTitleText() {
        return businessTitleText;
    }

    public void setBusinessTitleText(String businessTitleText) {
        this.businessTitleText = businessTitleText;
    }

    public String getJobCode() {
        return jobCode;
    }

    public void setJobCode(String jobCode) {
        this.jobCode = jobCode;
    }

    public String getSupervisorSesaId() {
        return supervisorSesaId;
    }

    public void setSupervisorSesaId(String supervisorSesaId) {
        this.supervisorSesaId = supervisorSesaId;
    }

    public String getBuHrSesaId() {
        return buHrSesaId;
    }

    public void setBuHrSesaId(String buHrSesaId) {
        this.buHrSesaId = buHrSesaId;
    }

    public String getCostCenter() {
        return costCenter;
    }

    public void setCostCenter(String costCenter) {
        this.costCenter = costCenter;
    }

    public String getEmployeeStatus() {
        return employeeStatus;
    }

    public void setEmployeeStatus(String employeeStatus) {
        this.employeeStatus = employeeStatus;
    }

    public String getEmployeeStatusText() {
        return employeeStatusText;
    }

    public void setEmployeeStatusText(String employeeStatusText) {
        this.employeeStatusText = employeeStatusText;
    }

    public String getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(String isEnable) {
        this.isEnable = isEnable;
    }

    public String getPhotoId() {
        return photoId;
    }

    public void setPhotoId(String photoId) {
        this.photoId = photoId;
    }

    public List<Org> getOrgs() {
        return orgs;
    }

    public void setOrgs(List<Org> orgs) {
        this.orgs = orgs;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public String[] getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(String[] roleIds) {
        this.roleIds = roleIds;
    }

    public List<Menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Menu> menus) {
        this.menus = menus;
    }

    public String[] getRoleNames() {
        return roleNames;
    }

    public void setRoleNames(String[] roleNames) {
        this.roleNames = roleNames;
    }
}
